<?php

if ((!defined('NV_SYSTEM')) AND (!defined('NV_ADMIN'))) {
    Header("Location: ../index.php");
    exit;
}
$content = "";
global $datafold,$module_name;
include INCLUDE_PATH."modules/Exchangerates/language/lang-vietnamese.php";
include INCLUDE_PATH."modules/Exchangerates/language/lang-english.php";

if($module_name!="Exchangerates") {
	/*Khai bao*/
	$url_get_content = 'http://www.vietcombank.com.vn/ExchangeRates/';//Link den trang thong tin ngoai te
	$sourcename = "VietComBank";//Ten nguon
	$pattern = '#<tr[^>]*>[\s\r\n\t]*<td[^>]*>[\s\r\n\t]*<font[^>]+>[\s\r\n\t]*([^<]+)[\s\r\n\t]*<br>[\s\r\n\t]*<\/font>[\s\r\n\t]*<\/td>[\s\r\n\t]*<td[^>]*>[\s\r\n\t]*<font[^>]+>[\s\r\n\t]*([^<]+)[\s\r\n\t]*<br>[\s\r\n\t]*<\/font>[\s\r\n\t]*<\/td>[\s\r\n\t]*<td[^>]*>[\s\r\n\t]*<font[^>]+>[\s\r\n\t]*([^<]+)[\s\r\n\t]*<br>[\s\r\n\t]*<\/font>[\s\r\n\t]*<\/td>[\s\r\n\t]*<td[^>]*>[\s\r\n\t]*<font[^>]+>[\s\r\n\t]*([^<]+)[\s\r\n\t]*<br>[\s\r\n\t]*<\/font>[\s\r\n\t]*<\/td>[\s\r\n\t]*<td[^>]*>[\s\r\n\t]*<font[^>]+>[\s\r\n\t]*([^<]+)[\s\r\n\t]*<br>[\s\r\n\t]*<\/font>[\s\r\n\t]*<\/td>[\s\r\n\t]*<\/tr>#si';//Cach loc thong tin
	/*Het phan khai bao*/
	
	$cache_file = INCLUDE_PATH . $datafold . '/exchangerates_' . md5($url_get_content).'.cache';
	$read_file = false;
	if(file_exists($cache_file) AND filesize($cache_file)!=0) {
		$timedif = @(time() - filemtime($cache_file));
		if ($timedif < 86400) {
			$read_file = true;
		}
	}
	clearstatcache();
	$unserialize = array();
	if($read_file) {
		$unserialize = unserialize(file_get_contents($cache_file));
	} else {
		$method = detect_openfile_methods();
		if(in_array('file_get_contents',$method)) {
			$method = 'file_get_contents';
		} else {
			$method = $method[0];
		}
		if($method!="") {
			$urlcontent = get_contents($url_get_content,$method);
			if($urlcontent!="") {
				preg_match_all($pattern,$urlcontent,$uns);
				unset($uns[0]);
				$unserialize['contents'] = array_values($uns);
				$unserialize['url'] = $url_get_content;
				$unserialize['urlname'] = $sourcename;
				$unserialize['updatetime'] = time();
				@$file = fopen($cache_file, "w");
				$serialized = serialize($unserialize);
				@fwrite($file, $serialized);
				@fclose($file);
			}
		}
	}
	
	if($unserialize!=array()) {
		$valutanames = $unserialize['contents'][0];
		$valutavalues = $unserialize['contents'][4];
		$content .= "<div style=\"height:326px;overflow:auto;\">\n";
		$content .= "<table border=\"0\" cellpadding=\"2\" style=\"border-collapse: collapse\" width=\"100%\" cellspacing=\"2\">\n";
		foreach($valutanames as $key => $valutaname) {
			$cl = ($key%2==0) ? '#EFEFEF' : '#FFFFFF';
			$content .= "<tr>\n";
			$content .= "<td bgcolor=\"$cl\" style=\"border: 1px solid #C0C0C0\">$valutaname</td>\n";
			$content .= "<td align=\"right\" bgcolor=\"$cl\" style=\"border: 1px solid #C0C0C0\">\n";
			$content .= "".$valutavalues[$key]."</td>\n";
			$content .= "</tr>\n";
		}
		$content .= "</table>\n";
		$content .= "</div>\n";
		$content .= "<div style=\"text-align: center\"><b><a href=\"modules.php?name=Exchangerates\">"._VIEWDETAIL."</a></b></div>\n";
	}
}

?>